package com.dog.basics.api.controller.mtkj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiDiscountCouponAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiDiscountCouponEditDto;
import com.dog.basics.bean.vo.api.mtkj.ApiDeviceDiscountCouponVo;
import com.dog.basics.bean.vo.api.mtkj.ApiDiscountCouponListVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtDiscountCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/api/discountCoupon")
@Api(value = "优惠券",tags = SwaggerConstants.API_ALL)
@AllArgsConstructor
public class MtDiscountCouponController {

    private final IMtDiscountCouponService discountCouponService;

    /**
     * 生成优惠券
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "生成优惠券", notes = "生成优惠券",tags = SwaggerConstants.API_DISCOUNT_COUPON)
    @PostMapping("/save")
    @Inner
    public R<Boolean> save(@Valid @RequestBody ApiDiscountCouponAddDto obj) {
        return R.ok(discountCouponService.saveDiscountCoupon(obj));
    }

    /**
     * 修改优惠券
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "修改优惠券", notes = "修改优惠券", tags = SwaggerConstants.API_DISCOUNT_COUPON)
    @PutMapping("/edit")
    @Inner
    public R<Boolean> edit(@Valid @RequestBody ApiDiscountCouponEditDto obj) {
        return R.ok(discountCouponService.editDiscountCoupon(obj));
    }


    /**
     * 删除优惠券
     * @param id
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "删除优惠券", notes = "删除优惠券", tags = SwaggerConstants.API_DISCOUNT_COUPON)
    @ApiImplicitParam(value = "优惠券Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @Inner
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(discountCouponService.deleteDiscountCoupon(id));
    }

    /**
     * 查询设备端优惠券
     * @param page
     * @return
     */
    @ApiOperation(value = "查询设备端优惠券", notes = "查询设备端优惠券", tags = SwaggerConstants.API_DEVICE_DISCOUNT_COUPON)
    @GetMapping("/getDevicePage")
    public R<IPage<ApiDeviceDiscountCouponVo>> getDevicePage(PageParam page){
        return R.ok(discountCouponService.findAppDiscountCoupon(page));
    }

    /**
     * 查询商铺优惠券
     * @param page
     * @param shopId
     * @return
     */
    @ApiOperation(value = "查询商铺优惠券", notes = "查询商铺优惠券", tags = SwaggerConstants.API_DISCOUNT_COUPON)
    @ApiImplicitParam(value = "商铺Id", name = "shopId", dataType = "Long", required = true)
    @GetMapping("/getByShopId/{shopId}")
    public R<IPage<ApiDiscountCouponListVo>> findByShopId(PageParam page , @Valid @PathVariable("shopId") Long shopId){
        return R.ok(discountCouponService.findByShopId(page,shopId));
    }

}
